package cn.getech.data.development.utils.ranger;

import cn.getech.data.development.config.properties.RangerConfig;
import cn.getech.data.development.service.RangerDataService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;

import javax.annotation.PostConstruct;

@Slf4j
@Configuration
@EnableScheduling
@ConditionalOnProperty(name = "data-development.websocket-open", havingValue = "true")
public class RangerDataTask {
    @Autowired
    private RangerConfig rangerConfig;
    @Autowired
    private RangerDataService rangerDataService;

    @Scheduled(cron = "0 0/10 * * * ?")
    public void initRangerClient() {
        //怕对应的是否超时
        RangerRestUtil.getInstanceRangerClient(rangerConfig.getUsername(), rangerConfig.getPassword());
    }

    /**
     * 项目启动时，初始化ranger连接
     */
    @PostConstruct
    public void init() {
        rangerDataService.init();
    }
}
